package com.second.task;


import com.second.mapper.FOrdSeckillMapper;
import com.second.model.pojo.FOrdSeckill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class SendReids {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private FOrdSeckillMapper seckillDao;

    //上架秒杀商品
    public void sendRedis() {
        //查出所有可以上架秒杀的商品（状态为0）
        List<FOrdSeckill> list = seckillDao.findAllByStatus(1);
        //定义一个redis的list name="seckill"+id value=[1,1,1,1,1,1]
        ListOperations vos = redisTemplate.opsForList();
        //给list赋值
        for (FOrdSeckill seckill : list) {
            Integer id = seckill.getId();
//            System.out.println(id);
            String name = "seckill" + id;
//            System.out.println(name);
            for (int i = 0; i < seckill.getNum(); i++) {
                vos.leftPush(name, id.toString());
            }
        }
    }

}
